package com.android.travellover;

import java.util.ArrayList;

import com.android.travellover.Item;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;


public class LiistItemActivity extends Activity {
	
	
	ListView listView;
	ListAdapter adapter;
	ArrayList<Item> listItem;	
	Button btnHome;
	Button btnAbout;
	Button btnSetting;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listitem);
        
        btnHome = (Button)findViewById(R.id.btnHome);
        btnAbout = (Button)findViewById(R.id.btnAbout);
        btnSetting = (Button)findViewById(R.id.btnSetting);
        
        btnHome.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getApplicationContext(), TravelLoverActivity.class);
				startActivity(intent);
				
			}
		});
        btnAbout.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getApplicationContext(), About.class);
				startActivity(intent);
				
			}
		});
        btnSetting.setOnClickListener(new OnClickListener() {
	
	public void onClick(View v) {
		// TODO Auto-generated method stub
		Intent intent = new Intent(getApplicationContext(), Setting.class);
		startActivity(intent);
		
			}
        });
        
        String sdPath = Environment.getExternalStorageDirectory() + "";
        String imgPath = sdPath + "\\" + "abc.jpg";

        listItem = new ArrayList<Item>();    
        listItem.add(new Item(imgPath, "Room"));
        listItem.add(new Item(imgPath, "A BCS"));
        listItem.add(new Item(imgPath, "Make love"));
        listItem.add(new Item(imgPath, "aa"));        
        adapter = new ListAdapter(getApplicationContext(), listItem);
        
        listView= (ListView)findViewById(R.id.listView1);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int posotion,
					long arg3) {
				
				// TODO Auto-generated method stub
				Item i = listItem.get(posotion);
				/*Toast.makeText(getApplicationContext(), i.name, Toast.LENGTH_SHORT).show();*/
				Intent intent = new Intent(getApplicationContext(), InformationActivity.class);
				intent.putExtra("NAME", i.name);
				startActivity(intent);
			}
		});                 
    }       
}